home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 21 / Mac Magazin and MacEasy Magazine CD - Issue 21.iso / Wissenschaft & Technik / yorick12vr1-nofpu folder / include / demo5.i < prev    next >
Text File  |  1996-02-29  |  5KB  |  175 lines

  1. /*
  2.    DEMO5.I
  3.    Demonstration of 3D plots with pl3d.i, plwf.i, slice3.i
  4.  
  5.    $Id$
  6.  */
  7. /*    Copyright (c) 1996.  The Regents of the University of California.
  8.                     All rights reserved.  */
  9.  
  10. require, "plwf.i"
  11. require, "slice3.i"
  12.  
  13. require, "movie.i";
  14.  
  15. window3;
  16. palette, "gray.gp";
  17.  
  18. func demo5(itest)
  19. /* DOCUMENT demo5
  20.          or demo5, i
  21.      Run examples of use of pl3d.i, plwf.i, and slice3.i.  With
  22.      argument I = 1, 2, or 3, run that particular demonstration.
  23.      Read the source code to understand the details of how the
  24.      various effects are obtained.
  25.  
  26.      demo5,1  demonstrates the various effects which can be obtained
  27.      with the plwf (plot wire frame) function.
  28.      demo5,2  demonstrates shading effects controlled by the light3
  29.      function
  30.      demo5,3  demonstrates the slice3, slice2, and pl3tree functions,
  31.      as well as changing the orientation of the 3D object
  32.  
  33.   SEE ALSO: plwf (plwf.i), light3, rot3, orient3, spin3 (pl3d.i),
  34.             mesh3, slice3, slice2, pl3tree, pl3surf (slice3.i)
  35.  */
  36. {
  37.   if (!itest || itest==1) {
  38.     x= span(-1,1,64)(,-:1:64);
  39.     y= transpose(x);
  40.     z= (x+y)*exp(-6*(x^2+y^2));
  41.     write, "(plot wire frame) plwf,z,y,x";
  42.     orient3;
  43.     light3;
  44.     plwf, z, y, x;
  45.     draw3,1;  /* not necessary interactively */
  46.     rdline,prompt="hit RETURN to continue";
  47.     write, "plwf,z,y,x, shade=1,ecolor=\"red\"";
  48.     plwf, z, y, x, shade=1,ecolor="red";
  49.     draw3,1;  /* not necessary interactively */
  50.     rdline,prompt="hit RETURN to continue";
  51.     limits;
  52.     write, "plwf,z,y,x, shade=1,edges=0";
  53.     plwf, z, y, x, shade=1,edges=0;
  54.     draw3,1;  /* not necessary interactively */
  55.     rdline,prompt="hit RETURN to continue";
  56.   }
  57.  
  58.   if (!itest || itest==2) {
  59.     x= span(-1,1,64)(,-:1:64);
  60.     y= transpose(x);
  61.     z= (x+y)*exp(-6*(x^2+y^2));
  62.     write, "light3 function demo- default lighting";
  63.     orient3;
  64.     light3;
  65.     plwf, z, y, x, shade=1,edges=0;
  66.     draw3,1;  /* not necessary interactively */
  67.     rdline,prompt="hit RETURN to continue";
  68.     write, "light3,diffuse=.2,specular=1";
  69.     light3,diffuse=.2,specular=1;
  70.     limits;
  71.     draw3,1;  /* not necessary interactively */
  72.     rdline,prompt="hit RETURN to continue";
  73.     write, "light3,sdir=[cos(theta),.25,sin(theta)]  -- movie";
  74.     movie, demo5_light;
  75.     fma; demo5_light, 1;
  76.     rdline,prompt="hit RETURN to continue";
  77.     light3;
  78.   }
  79.  
  80.   if (!itest || itest==3) {
  81.     nx= demo5_n(1);
  82.     ny= demo5_n(2);
  83.     nz= demo5_n(3);
  84.     xyz= array(0.0, 3, nx,ny,nz);
  85.     xyz(1,..)= span(-1,1,nx);
  86.     xyz(2,..)= span(-1,1,nx)(-,);
  87.     xyz(3,..)= span(-1,1,nx)(-,-,);
  88.     r= abs(xyz(1,..),xyz(2,..),xyz(3,..));
  89.     theta= acos(xyz(3,..)/r);
  90.     phi= atan(xyz(2,..),xyz(1,..)+(!r));
  91.     y32= sin(theta)^2*cos(theta)*cos(2*phi);
  92.     m3= mesh3(xyz, r*(1.+y32));
  93.     r= theta= phi= xyz= y32= [];
  94.  
  95.     write, "   test uses "+pr1((nx-1)*(ny-1)*(nz-1))+" cells";
  96.     elapsed= [0.,0.,0.];
  97.     timer, elapsed;
  98.     elapsed0= elapsed;
  99.  
  100.     slice3, m3, 1,value=.5, nv,xyzv;  /* inner isosurface */
  101.     slice3, m3, 1,value=1., nw,xyzw;  /* outer isosurface */
  102.     pxy= plane3([0,0,1],[0,0,0]);
  103.     pyz= plane3([1,0,0],[0,0,0]);
  104.     vp= slice3(m3, pyz, np,xyzp, 1);  /* pseudo-colored slice */
  105.     local nvb,xyzvb,nwb,xyzwb;
  106.     slice2, pxy, np,xyzp,vp;          /* cut slice in half */
  107.     slice2x, pxy, nv,xyzv,, nvb,xyzvb;  /* split inner in halves */
  108.     slice2, -pyz, nv,xyzv;       /* ...halve one of those halves */
  109.     slice2x, pxy, nw,xyzw,, nwb,xyzwb;  /* split outer in halves */
  110.     slice2, -pyz, nw,xyzw;       /* ...halve one of those halves */
  111.  
  112.     timer, elapsed;
  113.     timer_print,"slicing time",elapsed-elapsed0;
  114.  
  115.     fma;
  116.     write, "split_palette,\"earth.gp\" -- generate palette for pl3tree";
  117.     split_palette, "earth.gp";
  118.     write, "gnomon -- turn on gnomon";
  119.     gnomon, 1;
  120.  
  121.     write, "pl3tree with 1 slicing plane, 2 isosurfaces";
  122.     clear3;
  123.     pl3tree, np,xyzp,vp,pyz;
  124.     pl3tree, nvb,xyzvb;
  125.     pl3tree, nwb,xyzwb;
  126.     pl3tree, nv,xyzv;
  127.     pl3tree, nw,xyzw;
  128.     orient3;
  129.     light3,diffuse=.2,specular=1;
  130.     limits;
  131.     demo5_light, 1;
  132.     rdline,prompt="hit RETURN to continue";
  133.  
  134.     write, "spin3 animated rotation, use rot3 or orient3 for one frame";
  135.     /* don't want limits to autoscale during animation */
  136.     lims= limits();
  137.     dx= 1.1*max(lims(2),-lims(1));
  138.     dy= 1.1*max(lims(4),-lims(3));
  139.     limits, -dx,dx,-dy,dy;
  140.     spin3;
  141.     limits;  /* back to autoscaling */
  142.     demo5_light, 1;
  143.     rdline,prompt="hit RETURN to continue";
  144.  
  145.     light3;
  146.     gnomon, 0;
  147.     palette, "gray.gp";
  148.   }
  149. }
  150.  
  151. demo5_n= [20,20,20];
  152.  
  153. /* movie frame display function for third demo5 */
  154. func demo5_light(i)
  155. {
  156.   if (i>=30) return 0;
  157.  
  158.   theta= pi/4 + (i-1)*2*pi/29;
  159.   light3, sdir=[cos(theta),.25,sin(theta)];
  160.  
  161.   /* without an explicit call to draw3, the light3 function would
  162.    * cause no changes until Yorick paused for input from the keyboard,
  163.    * since unlike the primitive plotting functions (plg, plf, plfp, ...)
  164.    * the fma call made by the movie function will not trigger the
  165.    * 3D display list
  166.    * any movie frame display function which uses the 3D drawing
  167.    * functions in pl3d.i will need to do this
  168.    * the !making_movie flag supresses the fma in draw3 if this function
  169.    * is called by movie (which issues its own fma), but allows it
  170.    * otherwise */
  171.   draw3, !making_movie;
  172.  
  173.   return 1;
  174. }
  175.